#!/bin/bash
#
# Slackware build script of openoffice.org language pack (binary repackaging)

# Copyright 2006-2007  Robby Workman  (http://rlworkman.net) 
# All rights reserved.
# 
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Thanks to Sandman1, Larhzu, and MacIver for early assistance.
# Thanks to Fred Emmott (http://slamd64.com) for some better code in a few
# places and ideas to include the Optimization Solver and disable javaldx.
# Thanks to eroc for the idea to include support for other languages.

# Edited by Jan Herrygers to make it a Slackware build script of
# openoffice.org language packs. 10 july 2007

PRGNAM=openoffice.org-langpack
VERSION=2.2.1
ARCH=noarch
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

# This should allow you to either pass a different value of OOLANG when you
# run the script or change it in this script.  Note that you will need to 
# have the correct tarball in the build directory for this to work...
OOLANG=${OOLANG:-nl}
PKG_LANG=$(echo $OOLANG | sed s/-/_/)	# Leave this alone

# Require the script to exit if any command fails
set -e

# Ignore this - it's just to get the toplevel directory name of the 
# extracted tarball archive
SOURCEDIR=$(tar -tzf $CWD/OOo_${VERSION}_LinuxIntel_langpack_${OOLANG}.tar.gz | head -1 | tr -d \/)
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SOURCEDIR
tar -xzf $CWD/OOo_${VERSION}_LinuxIntel_langpack_${OOLANG}.tar.gz || exit 1
cd $SOURCEDIR/RPMS/
for FILE in *.rpm ; do rpm2cpio < $FILE | cpio -imdv ; done
mv opt $PKG
cd $PKG

# Move docs to their correct locations
mkdir -p $PKG/usr/doc/$PRGNAM-${VERSION}_${PKG_LANG}
for i in readmes licenses ; do
  mv $PKG/opt/openoffice.org2.2/$i \
    $PKG/usr/doc/$PRGNAM-${VERSION}_${PKG_LANG}/$i ;
done
cat $CWD/$PRGNAM.SlackBuild > \
  $PKG/usr/doc/$PRGNAM-${VERSION}_${PKG_LANG}$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

# Fix ownership and permissions and make the package
chown -R root:root .
find . -type d -exec chmod 755 {} \;
chmod -R u+rw,go+r-w,a-s .
/sbin/makepkg -c n -l y $OUTPUT/$PRGNAM-${VERSION}_${PKG_LANG}-$ARCH-$BUILD$TAG.tgz
